package cn.foolishbird.crow.sequence;

import cn.foolishbird.crow.core.CrowEnum;
import org.apache.commons.lang3.StringUtils;

/**
 * @author foolishbird
 * @version 1.0
 */
public abstract class AbstractPrefixSequenceStrategy implements SequenceStrategy {


    private Enum<? extends CrowEnum> identity;

    public AbstractPrefixSequenceStrategy(Enum<? extends CrowEnum> identity) {
        this.identity = identity;
    }


    @Override
    public Enum<? extends CrowEnum> identity() {
        return this.identity;
    }

    @Override
    public final String createSequence(String prefix) {
        String sequence = doCreateSequence();
        return StringUtils.isBlank(prefix) ? sequence : prefix + sequence;
    }

    /**
     * 创建序号
     *
     * @return
     */
    protected abstract String doCreateSequence();
}
